package com.eleventwelve.iris.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.opentides.util.StringUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.eleventwelve.iris.entity.Patient;
import com.eleventwelve.iris.service.PatientService;

/**
 * 
 * @author Ashley
 *
 */
public class PatientDetailsController extends AbstractController{
	private String viewName;
	private PatientService patientService;
	private String jasperPath;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		Patient patient = null;
		
		
		String patientId = request.getParameter("id");
		if(!StringUtil.isEmpty(patientId) && StringUtils.isNumeric(patientId)){
			patient = patientService.load(patientId);
		}
		
		map.put("jasperPath", jasperPath);
		
		if(patient!=null){
			map.put("patient", patient);
			return new ModelAndView(viewName, map);
		} else {
			return new ModelAndView(viewName); //should redirect to error page
		}
		
		
		
		
	}


	public String getViewName() {
		return viewName;
	}


	public void setViewName(String viewName) {
		this.viewName = viewName;
	}


	public PatientService getPatientService() {
		return patientService;
	}


	public void setPatientService(PatientService patientService) {
		this.patientService = patientService;
	}
	
	public void setJasperPath(String jasperPath) {
		this.jasperPath = jasperPath;
	}

}
